import React, { Component } from 'react'
import { homelist } from '../../api/index'
export default class Home extends Component {
  state = {
    homelist: [],
  }

  getList() {
    homelist().then((res) => {
      console.log(res);
      // this.setState({
      //     homelist: res.data.data,
      // });
      if (res.data.code === 200) {
        this.setState({
          homelist: res.data.data,
        });
      } else {
        this.props.history.push('/login')
        window.sessionStorage.clear()
      }
    });
  }
  componentDidMount() {
    this.getList();
  }
  render() {

    const { homelist } = this.state

    return (
      <div className='home'>
        <div className="home_main">
          {
            homelist ? homelist.map((item, index) => {
              return <div key={index} className='homelist'>
                <dl >
                  <dt>
                    <img src={item.img} alt="" />
                  </dt>
                  <dd>
                    <p>{item.title}</p>
                    <p>{item.time}</p>
                  </dd>
                </dl>
              </div>
            }) : null
          }
        </div>
      </div>
    )
  }
}
